class Spromise{
	constructor(fn) {
		this.actions = [];
		let _resolve = (val)=>{
			let tem = val;
			let status = true;
			for(let i in this.actions){
				ac = this.actions[i]
				if(!status){
					if(ac.type != 'catch') continue
				}else{
					if(ac.type != 'then') continue
				}
				try{
					tem = ac(tem);
					status = true
				}catch(e){
					status = false
					tem = e
					continue
				}
			}
		}
		_reject = (e)=>{
			let tem = val;
			let status = true;
			for(let i in this.actions){
				ac = this.actions[i]
				if(!status){
					if(ac.type != 'catch') continue
				}
				try{
					tem = ac(tem);
				}catch(e){
					status = false
					continue
					
				}
			}
			return this
		}
		setTimeout(()=>{
			fn(_resolve, _reject);
		})
	}
	then(cb){
		let fn = (val)=>{
			return cb(val);
		}
		fn.type = 'then'
		this.actions.push(fn)
		return this;
	}
	catch(cb){
		let fn = (val)=>{
			return cb(val);
		}
		fn.type = 'catch'
		this.actions.push(fn)
		return this;
	}
}

new Spromise((resolve, reject)=>{
	setTimeout(()=>{
		resolve("nnn")
	})
}).then((res)=>{
	console.log(res, 'res1')
	return "info"
})
.then((res)=>{
	console.log(res, 'res2')
	return "info"
}).then((res)=>{
	console.log(res, 'res3', zz)
	return "info"
}).catch((err)=>{
	console.log(err, 'eee1')
}).catch((err)=>{
	console.log(err, 'eee2')
}).then((res)=>{
	console.log(res, 'res4', jj)
	return "info"
}).catch((err)=>{
	console.log(err, 'eee3')
})
